<template>
    <Card>
        <p slot="title">技师申请</p>
        <div class="search-con search-con-top">
            技师信息：
            <Input v-model="search.search" placeholder="名称、手机号" style="width: 200px"></Input>
            入驻时间：
            <DatePicker type="date" v-model="search.start_time" placeholder="开始时间" style="width: 200px"></DatePicker>
            <span style="margin: 0 3px;">-</span>
            <DatePicker type="date" v-model="search.end_time" placeholder="结束时间" style="width: 200px"></DatePicker>
            <Button type="primary" icon="ios-search" style="margin-left: 10px;" @click="getList">搜索</Button>
            <Button @click="reset" type="success" icon="ios-refresh" style="margin-left: 10px;">刷新</Button>
        </div>
        <Table :columns="columns" :data="list" ref="selection" border style="margin-top: 10px;">
            <template slot-scope="{ row , index}" slot="avatarSlot">
                <img :src="baseImgeUrl + row.avatar" style="width: 60px;height: 60px;" @click="showImg(baseUrl + row.avatar)" />
            </template>
            <template slot-scope="{ row , index}" slot="auth">
                {{ row.is_auth === 1 ? '已认证' : '未认证' }}
            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <Button type="primary" size="small" @click="audit(row.id, 1)">通过</Button>
                <Button type="error" size="small" style="margin-left: 10px;" @click="audit(row.id, 2)">驳回</Button>
            </template>
        </Table>
        <br>

        <Page :total="total" show-sizer show-total show-elevator @on-change="changePage" @on-page-size-change="changeSize">
        </Page>
        <Modal v-model="imgShow" width="330px" :closable="false">
            <img :src="imgShowUrl" style="width: 300px;">
        </Modal>
    </Card>
</template>
  
<script>
import config from "@/config";
import { getToken } from "../../libs/util";
const baseUrl = process.env.NODE_ENV === "development" ? config.baseUrl.dev : config.baseUrl.pro;
const baseImgeUrl = process.env.NODE_ENV === "development" ? config.baseImgUrl.dev : config.baseImgUrl.pro;
export default {
    name: "technicianApply",
    data() {
        return {
            baseUrl: baseUrl,
            baseImgeUrl: baseImgeUrl,
            action_url: baseUrl + "/admin/image/uploadImg",
            // 列表
            columns: [
                {
                    title: 'ID',
                    align:"center",
                    key: 'id',
                },
                {
                    title: '头像',
                    align:"center",
                    key: 'avatar',
                    slot: "avatarSlot"
                }, {
                    title: '昵称',
                    align:"center",
                    key: 'username',
                }, {
                    title: '入驻类型',
                    align:"center",
                    key: 'type_title',
                },
                {
                    title: '性别',
                    align:"center",
                    key: 'gender',
                },
                {
                    title: '年龄',
                    align:"center",
                    key: 'age',
                },
                {
                    title: '手机号',
                    align:"center",
                    key: 'mobile',
                },
                // {
                //     title: '状态',
                //     align:"center",
                //     key: 'is_auth',
                //     slot: "auth"
                // },
                {
                    title: '所属区域',
                    align:"center",
                    key: 'address',
                },
                {
                    title: '申请时间',
                    align:"center",
                    key: 'create_time',
                },
                {
                    title: '操作',
                    align:"center",
                    slot: 'makeSlot',
                },
            ],
            // 数据
            list: [],
            total: 0,
            imgShow: false,
            imgShowUrl: '',
            search: {
                search: "",
                start_time: "",
                end_time: "",
                page: "",
                limit: ""
            },
        }
    },
    methods: {
        // 查询技师信息
        getList() {
            this.$axios('/admin/tec/getApplyList', this.search).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        searchs() {
            this.search.page = 1;
            this.getList();
        },
        reset() {
            this.search.search = "";
            this.search.start_time = "";
            this.search.end_time = "";
            this.getList();
        },
        changePage(page) {
            this.search.page = page;
            this.getList();
        },
        changeSize(size) {
            this.search.limit = size;
            this.getList();
        },
        showImg(url) {
            this.imgShow = true;
            this.imgShowUrl = url;
        },
        // 获取技师等级
        audit(id, status) {
            let txt = "";
            if (status == 1) {
                txt = "<p>您确定要审核通过吗？</p>"
            } else {
                txt = "<p>您确定要审核拒绝吗？</p>"
            }
            this.$Modal.confirm({
                title: '审核技师',
                content: txt,
                onOk: () => {
                    this.$axios('/admin/tec/pass', { id: id, status: status }).then(res => {
                        this.$Message.success('审核成功');
                        this.getList();
                    });
                },
                onCancel: () => {
                    this.$Message.info('取消操作');
                }
            });
        }
    },
    created() {
        this.getList();
    }
}
</script>
<style>
.ivu-table-cell {
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>
  